﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace Quản_Lý_Thư_Viện
{
    class CTPMdataaccess
    {
        private DataProvider _provider = new DataProvider();
        public CTPMdataaccess()
        {
            _provider.connect();
        }
        public void insertctpm(CTPMinfo info)
        {
            string insertCommand = "insert into dbo.CT_PMS values ('"+info.Masach+"','"+info.Mapm+"')";
            _provider.executeNonQuery(insertCommand);
            
        }
        public void deletectpm(CTPMinfo info)
        {
            string deleteCommand = "delete from dbo.CT_PMS where MASACH = '" + info.Masach + "'";
            _provider.executeNonQuery(deleteCommand);
        }
        public DataTable layctpms(CTPMinfo info)
        {
            return _provider.GetData("select CT_PMS.MASACH,MAPMS from CT_PMS,SACH where SACH.MASACH = CT_PMS.MASACH and TINHTRANG = 'Da cho muon' and CT_PMS.MASACH = '" + info.Masach + "' order by MAPMS desc ");
        }
        public DataTable sachdamuon()
        {
            return _provider.GetData("Select dbo.CT_PMS.MASACH , TENSACH , NGMUON,NGTRAQD from dbo.PHIEUMUONSACH,dbo.CT_PMS,dbo.DAUSACH,dbo.SACH where dbo.PHIEUMUONSACH.MAPMS = dbo.CT_PMS.MAPMS and dbo.DAUSACH.MADAUSACH = dbo.SACH.MADAUSACH and dbo.SACH.MASACH = dbo.CT_PMS.MASACH and MADG = '" + FrmDangNhap.madg + "' ");
        }
        public DataTable sosachdgdamuon()
        {
            return _provider.GetData("select count(MASACH) from dbo.CT_PMS, dbo.PHIEUMUONSACH where dbo.CT_PMS.MAPMS = dbo.PHIEUMUONSACH.MAPMS and MADG = '" + frmMuonSach.madg + "'");
        }
    }
}
